package com.webwork.lims.transport.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webwork.lims.transport.dao.WaysDao;
import com.webwork.lims.transport.dataobject.Ways;
import com.webwork.lims.transport.service.WaysService;
import com.webwork.lims.util.Paging;

@Service
public class WaysServiceImpl implements WaysService {

	@Autowired
	private WaysDao wayDao;

	@Override
	public List<Ways> query(Ways queryObj) {
		return this.query(queryObj, new Paging(0, 0));
	}

	@Override
	public int count(Ways queryObj) {
		return wayDao.count(queryObj);
	}

	@Override
	public List<Ways> query(Ways queryObj, Paging paging) {
		return wayDao.query(queryObj, paging.getCurrPage(), paging.getPageSize());
	}

	@Override
	public Ways get(int id) {
		Ways queryObj = new Ways();
		queryObj.setWayCode(id);
		List<Ways> ways = this.query(queryObj);
		if (ways != null && ways.size() > 0) {
			if (ways.size() > 1) {
				System.out.println("存在不止一条记录!");
			} else {
				return ways.get(0);
			}
		} else {
			System.out.println("找不到该地区!");
		}
		return null;
	}

	@Override
	public void insert(Ways way) {
		wayDao.insert(way);
	}

	@Override
	public void update(Ways way) {
		wayDao.update(way);
	}

	@Override
	public void save(Ways way) {
		if (this.get(way.getWayCode()) != null) {
			this.update(way);
		} else {
			this.insert(way);
		}
	}

	@Override
	public void delete(int id) {
		wayDao.delete(id);
	}
	
}
